package logic

import (
	"context"
	"month2/B/rpc_B/model/mysql"

	"month2/B/rpc_B/internal/svc"
	"month2/B/rpc_B/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *user.GoodsListRequest) (*user.GoodsListResponse, error) {
	var goods []*mysql.Goods2
	mysql.DB.Where("status=?", in.Status).Find(&goods)
	var list []*user.GoodsList
	for _, v := range goods {
		userList := user.GoodsList{
			GoodsName:  v.GoodsName,
			GoodsPrice: float32(v.GoodsPrice),
			GoodsNum:   int64(v.GoodsNum),
			GoodsImg:   v.GoodsImg,
			Status:     int64(v.Status),
		}
		list = append(list, &userList)
	}
	return &user.GoodsListResponse{
		List: list,
	}, nil
}
